<!DOCTYPE html>
<html lang="en-us" dir="ltr">
    <head><meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'><meta name='description' content='centos7更换源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
检查nginx.conf sudo nginx -t -c /etc/nginx/nginx.conf
在centos7下运行nginx systemctl restart nginx ps -ef|grep nginx
kill 80或443端口 sudo fuser -k 80/tcp sudo fuser -k 443/tcp
nginx的https配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # For more information on configuration, see: # * Official English Documentation: http://nginx.'><title>nginx和centos</title>

<link rel='canonical' href='http://meruro.cn/p/nginx%E5%92%8Ccentos/'>

<link rel="stylesheet" href="/scss/style.min.5a8e892f6fa14515e9065eee1f5d2e05302606ec7f11750b2fb95198f9cdcbfd.css"><meta property='og:title' content='nginx和centos'>
<meta property='og:description' content='centos7更换源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
检查nginx.conf sudo nginx -t -c /etc/nginx/nginx.conf
在centos7下运行nginx systemctl restart nginx ps -ef|grep nginx
kill 80或443端口 sudo fuser -k 80/tcp sudo fuser -k 443/tcp
nginx的https配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # For more information on configuration, see: # * Official English Documentation: http://nginx.'>
<meta property='og:url' content='http://meruro.cn/p/nginx%E5%92%8Ccentos/'>
<meta property='og:site_name' content='梅鲁梅鲁梅鲁梅~'>
<meta property='og:type' content='article'><meta property='article:section' content='Post' /><meta property='article:tag' content='代码' /><meta property='article:published_time' content='2018-06-18T22:00:07&#43;00:00'/><meta property='article:modified_time' content='2018-06-18T22:00:07&#43;00:00'/>
<meta name="twitter:title" content="nginx和centos">
<meta name="twitter:description" content="centos7更换源 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
检查nginx.conf sudo nginx -t -c /etc/nginx/nginx.conf
在centos7下运行nginx systemctl restart nginx ps -ef|grep nginx
kill 80或443端口 sudo fuser -k 80/tcp sudo fuser -k 443/tcp
nginx的https配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # For more information on configuration, see: # * Official English Documentation: http://nginx.">
    </head>
    <body class="
    article-page
    ">
    <script>
        (function() {
            const colorSchemeKey = 'StackColorScheme';
            if(!localStorage.getItem(colorSchemeKey)){
                localStorage.setItem(colorSchemeKey, "auto");
            }
        })();
    </script><script>
    (function() {
        const colorSchemeKey = 'StackColorScheme';
        const colorSchemeItem = localStorage.getItem(colorSchemeKey);
        const supportDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches === true;

        if (colorSchemeItem == 'dark' || colorSchemeItem === 'auto' && supportDarkMode) {
            

            document.documentElement.dataset.scheme = 'dark';
        } else {
            document.documentElement.dataset.scheme = 'light';
        }
    })();
</script>
<div class="container main-container flex on-phone--column extended"><aside class="sidebar left-sidebar sticky ">
    <button class="hamburger hamburger--spin" type="button" id="toggle-menu" aria-label="Toggle Menu">
        <span class="hamburger-box">
            <span class="hamburger-inner"></span>
        </span>
    </button>

    <header>
        
            
            <figure class="site-avatar">
                <a href="/">
                
                    
                    
                    
                        
                        <img src="/img/ava_hu31add2dceb44736f969f74989490346b_19511_300x0_resize_q75_box.jpg" width="300"
                            height="300" class="site-logo" loading="lazy" alt="Avatar">
                    
                
                </a>
                
                    <span class="emoji">🍥</span>
                
            </figure>
            
        
        
        <div class="site-meta">
            <h1 class="site-name"><a href="/">梅鲁梅鲁梅鲁梅~</a></h1>
            <h2 class="site-description">朝闻道,夕死可矣.</h2>
        </div>
    </header><ol class="social-menu">
            
                <li>
                    <a 
                        href='https://github.com/CaiJimmy/hugo-theme-stack'
                        target="_blank"
                        title="GitHub"
                    >
                        
                        
                            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-github" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
  <path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5" />
</svg>



                        
                    </a>
                </li>
            
                <li>
                    <a 
                        href='https://twitter.com'
                        target="_blank"
                        title="Twitter"
                    >
                        
                        
                            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-twitter" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
  <path d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z" />
</svg>



                        
                    </a>
                </li>
            
        </ol><ol class="menu" id="main-menu">
        
        
        

        <li >
            <a href='/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-home" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <polyline points="5 12 3 12 12 3 21 12 19 12" />
  <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
</svg>



                
                <span>Home</span>
            </a>
        </li>
        
        

        <li >
            <a href='/about/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-user" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="7" r="4" />
  <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
</svg>



                
                <span>About</span>
            </a>
        </li>
        
        

        <li >
            <a href='/archives/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-archive" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <rect x="3" y="4" width="18" height="4" rx="2" />
  <path d="M5 8v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-10" />
  <line x1="10" y1="12" x2="14" y2="12" />
</svg>



                
                <span>Archives</span>
            </a>
        </li>
        
        

        <li >
            <a href='/search/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-search" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="10" cy="10" r="7" />
  <line x1="21" y1="21" x2="15" y2="15" />
</svg>



                
                <span>Search</span>
            </a>
        </li>
        
        

        <li >
            <a href='/links/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5" />
  <path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5" />
</svg>



                
                <span>Links</span>
            </a>
        </li>
        

        <div class="menu-bottom-section">
                <li id="i18n-switch">  
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-language" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
  <path d="M4 5h7" />
  <path d="M9 3v2c0 4.418 -2.239 8 -5 8" />
  <path d="M5 9c-.003 2.144 2.952 3.908 6.7 4" />
  <path d="M12 20l4 -9l4 9" />
  <path d="M19.1 18h-6.2" />
</svg>



                    <select name="language" onchange="window.location.href = this.selectedOptions[0].value">
                        
                            <option value="http://meruro.cn/" selected>English</option>
                        
                            <option value="http://meruro.cn/zh-cn/" >中文</option>
                        
                            <option value="http://meruro.cn/ar/" >عربي</option>
                        
                    </select>
                </li>
            
            
            
                <li id="dark-mode-toggle">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-toggle-left" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="8" cy="12" r="2" />
  <rect x="2" y="6" width="20" height="12" rx="6" />
</svg>



                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-toggle-right" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="16" cy="12" r="2" />
  <rect x="2" y="6" width="20" height="12" rx="6" />
</svg>



                    <span>Dark Mode</span>
                </li>
            
        </div>
    </ol>
</aside>
<main class="main full-width">
    <article class="main-article">
    <header class="article-header">

    <div class="article-details">
    

    <div class="article-title-wrapper">
        <h2 class="article-title">
            <a href="/p/nginx%E5%92%8Ccentos/">nginx和centos</a>
        </h2>
    
        
    </div>

    
    <footer class="article-time">
        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-calendar-time" width="56" height="56" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" />
  <circle cx="18" cy="18" r="4" />
  <path d="M15 3v4" />
  <path d="M7 3v4" />
  <path d="M3 11h16" />
  <path d="M18 16.496v1.504l1 1" />
</svg>
                <time class="article-time--published">Jun 18, 2018</time>
            </div>
        

        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clock" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="12" r="9" />
  <polyline points="12 7 12 12 15 15" />
</svg>



                <time class="article-time--reading">
                    4 minute read
                </time>
            </div>
        
    </footer>
    

    
</div>
</header>

    <section class="article-content">
    
    
    <h1 id="centos7更换源">centos7更换源</h1>
<p>mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo <a class="link" href="https://mirrors.aliyun.com/repo/Centos-7.repo"  target="_blank" rel="noopener"
    >https://mirrors.aliyun.com/repo/Centos-7.repo</a></p>
<h1 id="检查nginxconf">检查nginx.conf</h1>
<p>sudo nginx -t -c /etc/nginx/nginx.conf</p>
<h1 id="在centos7下运行nginx">在centos7下运行nginx</h1>
<p>systemctl restart nginx
ps -ef|grep nginx</p>
<h1 id="kill-80或443端口">kill 80或443端口</h1>
<p>sudo fuser -k 80/tcp
sudo fuser -k 443/tcp</p>
<h1 id="nginx的https配置">nginx的https配置</h1>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># For more information on configuration, see:</span>
</span></span><span class="line"><span class="cl"><span class="c1">#   * Official English Documentation: http://nginx.org/en/docs/</span>
</span></span><span class="line"><span class="cl"><span class="c1">#   * Official Russian Documentation: http://nginx.org/ru/docs/</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">user nginx<span class="p">;</span>
</span></span><span class="line"><span class="cl">worker_processes auto<span class="p">;</span>
</span></span><span class="line"><span class="cl">error_log /var/log/nginx/error.log<span class="p">;</span>
</span></span><span class="line"><span class="cl">pid /run/nginx.pid<span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.</span>
</span></span><span class="line"><span class="cl">include /usr/share/nginx/modules/*.conf<span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">events <span class="o">{</span>
</span></span><span class="line"><span class="cl">    worker_connections 1024<span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="o">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">http <span class="o">{</span>
</span></span><span class="line"><span class="cl">    log_format  main  <span class="s1">&#39;$remote_addr - $remote_user [$time_local] &#34;$request&#34; &#39;</span>
</span></span><span class="line"><span class="cl">                      <span class="s1">&#39;$status $body_bytes_sent &#34;$http_referer&#34; &#39;</span>
</span></span><span class="line"><span class="cl">                      <span class="s1">&#39;&#34;$http_user_agent&#34; &#34;$http_x_forwarded_for&#34;&#39;</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    access_log  /var/log/nginx/access.log  main<span class="p">;</span>
</span></span><span class="line"><span class="cl">	
</span></span><span class="line"><span class="cl">    sendfile            on<span class="p">;</span>
</span></span><span class="line"><span class="cl">    tcp_nopush          on<span class="p">;</span>
</span></span><span class="line"><span class="cl">    tcp_nodelay         on<span class="p">;</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h1 id="centos7-下通过nginxuwsgi部署django应用">centos7 下通过nginx+uwsgi部署django应用</h1>
<h2 id="1-安装python36">1. 安装python3.6</h2>
<p>提前安装好系统依赖包：
centos: 
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++  openssl-devel libffi-devel python-devel mariadb-devel
ubuntu:
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev default-libmysqlclient-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev</p>
<ol>
<li>获取</li>
</ol>
<p>wget <a class="link" href="https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz"  target="_blank" rel="noopener"
    >https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz</a>
tar -xzvf Python-3.6.2.tgz -C  /tmp
cd  /tmp/Python-3.6.2/</p>
<ol start="2">
<li>把Python3.6安装到 /usr/local 目录</li>
</ol>
<p>./configure &ndash;prefix=/usr/local
make
make altinstall</p>
<ol start="3">
<li>更改/usr/bin/python链接</li>
</ol>
<p>ln -s /usr/local/bin/python3.6 /usr/bin/python3</p>
<h2 id="2-maridb">2. maridb</h2>
<ol>
<li>安装
sudo yum install mariadb-server</li>
<li>启动， 重启
sudo systemctl start mariadb
sudo systemctl restart mariadb</li>
<li>设置bind-ip
vim /etc/my.cnf
在 [mysqld]:
下面加一行
bind-address = 0.0.0.0</li>
<li>设置外部ip可以访问
先进入mysql才能运行下面命令:
mysql 直接进入就行
GRANT ALL PRIVILEGES ON <em>.</em> TO &lsquo;zby&rsquo;@&rsquo;localhost&rsquo; IDENTIFIED BY &lsquo;zzzz&rsquo; WITH GRANT OPTION;
FLUSH PRIVILEGES</li>
<li>设置阿里云的对外端口
视频中有讲解这部分</li>
<li>安装mysqlclient出问题
centos 7：
yum install python-devel mariadb-devel -y
ubuntu：
sudo apt-get install libmysqlclient-dev
然后：
pip install mysqlclient</li>
</ol>
<h2 id="3-安装nginx">3. 安装nginx</h2>
<p><a class="link" href="https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7"  target="_blank" rel="noopener"
    >https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7</a>
4. 安装virtualenvwrapper
yum install python-setuptools python-devel
pip install virtualenvwrapper
编辑.bashrc文件
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
重新加载.bashrc文件
source  ~/.bashrc
新建虚拟环境
mkvirtualenv mxonline
进入虚拟环境 
workon mxonline
安装pip包
我们可以通过 pip freeze &gt; requirements.txt 将本地的虚拟环境安装包相信信息导出来</p>
<p>然后将requirements.txt文件上传到服务器之后运行：</p>
<p>pip install -r requirements.txt
安装依赖包
5. 安装uwsgi
pip install uwsgi
6. 测试uwsgi
uwsgi &ndash;http :8000 &ndash;module MxOnline.wsgi
7. 配置nginx
新建uc_nginx.conf</p>
<h2 id="配置文件">配置文件</h2>
<p>#the upstream component nginx needs to connect to
upstream django {</p>
<h1 id="server-unixpathtoyourmysitemysitesock--for-a-file-socket">server unix:///path/to/your/mysite/mysite.sock; # for a file socket</h1>
<p>server 127.0.0.1:8000; # for a web port socket (we&rsquo;ll use this first)
}
#configuration of the server
server {
#the port your site will be served on
listen      80;
#the domain name it will serve for
server_name 你的ip地址 ; # substitute your machine&rsquo;s IP address or FQDN
charset     utf-8;</p>
<p>#max upload size
client_max_body_size 75M;   # adjust to taste</p>
<p>#Django media
location /media  {
alias 你的目录/Mxonline/media;  # 指向django的media目录
}</p>
<p>location /static {
alias 你的目录/Mxonline/static; # 指向django的static目录
}</p>
<h2 id="发送所有请求经uwsgi转接">发送所有请求经uwsgi转接</h2>
<p>location / {
uwsgi_pass  django;
include     uwsgi_params; # the uwsgi_params file you installed
}
}
8. 将该配置文件加入到nginx的启动配置文件中
sudo ln -s 你的目录/Mxonline/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/
8. 拉取所有需要的static file 到同一个目录
在django的setting文件中，添加下面一行内容：</p>
<pre><code>STATIC_ROOT = os.path.join(BASE_DIR, &quot;static/&quot;)
</code></pre>
<p>运行命令
python manage.py collectstatic
9. 运行nginx
sudo /usr/sbin/nginx
这里需要注意 一定是直接用nginx命令启动， 不要用systemctl启动nginx不然会有权限问题</p>
<ol start="10">
<li>通过配置文件启动uwsgi
新建uwsgi.ini 配置文件， 内容如下：
<h1 id="mysite_uwsgiini-file">mysite_uwsgi.ini file</h1>
[uwsgi]
<h1 id="django-related-settings">Django-related settings</h1>
<h1 id="the-base-directory-full-path">the base directory (full path)</h1>
chdir           = /home/bobby/Projects/MxOnline
<h1 id="djangos-wsgi-file">Django&rsquo;s wsgi file</h1>
module          = MxOnline.wsgi
<h1 id="the-virtualenv-full-path">the virtualenv (full path)</h1>
<h1 id="process-related-settings">process-related settings</h1>
<h1 id="master">master</h1>
master          = true
<h1 id="maximum-number-of-worker-processes">maximum number of worker processes</h1>
processes       = 10
<h1 id="the-socket-use-the-full-path-to-be-safe">the socket (use the full path to be safe</h1>
socket          = 127.0.0.1:8000
<h1 id="-with-appropriate-permissions---may-be-needed">&hellip; with appropriate permissions - may be needed</h1>
<h1 id="chmod-socket-----664">chmod-socket    = 664</h1>
<h1 id="clear-environment-on-exit">clear environment on exit</h1>
vacuum          = true
virtualenv = /home/bobby/.virtualenvs/mxonline
logto = /tmp/mylog.log</li>
</ol>
<p>注：
chdir： 表示需要操作的目录，也就是项目的目录
module： wsgi文件的路径
processes： 进程数
virtualenv：虚拟环境的目录</p>
<p>workon mxonline
uwsgi -i 你的目录/Mxonline/conf/uwsgi.ini &amp;
访问
http://你的ip地址/</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">  1
</span><span class="lnt">  2
</span><span class="lnt">  3
</span><span class="lnt">  4
</span><span class="lnt">  5
</span><span class="lnt">  6
</span><span class="lnt">  7
</span><span class="lnt">  8
</span><span class="lnt">  9
</span><span class="lnt"> 10
</span><span class="lnt"> 11
</span><span class="lnt"> 12
</span><span class="lnt"> 13
</span><span class="lnt"> 14
</span><span class="lnt"> 15
</span><span class="lnt"> 16
</span><span class="lnt"> 17
</span><span class="lnt"> 18
</span><span class="lnt"> 19
</span><span class="lnt"> 20
</span><span class="lnt"> 21
</span><span class="lnt"> 22
</span><span class="lnt"> 23
</span><span class="lnt"> 24
</span><span class="lnt"> 25
</span><span class="lnt"> 26
</span><span class="lnt"> 27
</span><span class="lnt"> 28
</span><span class="lnt"> 29
</span><span class="lnt"> 30
</span><span class="lnt"> 31
</span><span class="lnt"> 32
</span><span class="lnt"> 33
</span><span class="lnt"> 34
</span><span class="lnt"> 35
</span><span class="lnt"> 36
</span><span class="lnt"> 37
</span><span class="lnt"> 38
</span><span class="lnt"> 39
</span><span class="lnt"> 40
</span><span class="lnt"> 41
</span><span class="lnt"> 42
</span><span class="lnt"> 43
</span><span class="lnt"> 44
</span><span class="lnt"> 45
</span><span class="lnt"> 46
</span><span class="lnt"> 47
</span><span class="lnt"> 48
</span><span class="lnt"> 49
</span><span class="lnt"> 50
</span><span class="lnt"> 51
</span><span class="lnt"> 52
</span><span class="lnt"> 53
</span><span class="lnt"> 54
</span><span class="lnt"> 55
</span><span class="lnt"> 56
</span><span class="lnt"> 57
</span><span class="lnt"> 58
</span><span class="lnt"> 59
</span><span class="lnt"> 60
</span><span class="lnt"> 61
</span><span class="lnt"> 62
</span><span class="lnt"> 63
</span><span class="lnt"> 64
</span><span class="lnt"> 65
</span><span class="lnt"> 66
</span><span class="lnt"> 67
</span><span class="lnt"> 68
</span><span class="lnt"> 69
</span><span class="lnt"> 70
</span><span class="lnt"> 71
</span><span class="lnt"> 72
</span><span class="lnt"> 73
</span><span class="lnt"> 74
</span><span class="lnt"> 75
</span><span class="lnt"> 76
</span><span class="lnt"> 77
</span><span class="lnt"> 78
</span><span class="lnt"> 79
</span><span class="lnt"> 80
</span><span class="lnt"> 81
</span><span class="lnt"> 82
</span><span class="lnt"> 83
</span><span class="lnt"> 84
</span><span class="lnt"> 85
</span><span class="lnt"> 86
</span><span class="lnt"> 87
</span><span class="lnt"> 88
</span><span class="lnt"> 89
</span><span class="lnt"> 90
</span><span class="lnt"> 91
</span><span class="lnt"> 92
</span><span class="lnt"> 93
</span><span class="lnt"> 94
</span><span class="lnt"> 95
</span><span class="lnt"> 96
</span><span class="lnt"> 97
</span><span class="lnt"> 98
</span><span class="lnt"> 99
</span><span class="lnt">100
</span><span class="lnt">101
</span><span class="lnt">102
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#user  nobody;</span>
</span></span><span class="line"><span class="cl">worker_processes  1<span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#error_log  logs/error.log;</span>
</span></span><span class="line"><span class="cl"><span class="c1">#error_log  logs/error.log  notice;</span>
</span></span><span class="line"><span class="cl"><span class="c1">#error_log  logs/error.log  info;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">#pid        logs/nginx.pid;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">events <span class="o">{</span>
</span></span><span class="line"><span class="cl">    worker_connections  1024<span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="o">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">http <span class="o">{</span>
</span></span><span class="line"><span class="cl">    include       mime.types<span class="p">;</span>
</span></span><span class="line"><span class="cl">    default_type  application/octet-stream<span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">#log_format  main  &#39;$remote_addr - $remote_user [$time_local] &#34;$request&#34; &#39;</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#                  &#39;$status $body_bytes_sent &#34;$http_referer&#34; &#39;</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#                  &#39;&#34;$http_user_agent&#34; &#34;$http_x_forwarded_for&#34;&#39;;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">#access_log  logs/access.log  main;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    sendfile        on<span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#tcp_nopush     on;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">#keepalive_timeout  0;</span>
</span></span><span class="line"><span class="cl">    keepalive_timeout  65<span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="c1">#gzip  on;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    server <span class="o">{</span>
</span></span><span class="line"><span class="cl">        listen       80<span class="p">;</span>
</span></span><span class="line"><span class="cl">        server_name  localhost<span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1">#charset koi8-r;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1">#access_log  logs/host.access.log  main;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        location / <span class="o">{</span>
</span></span><span class="line"><span class="cl">            uwsgi_pass   django<span class="p">;</span>
</span></span><span class="line"><span class="cl">            includ       uwsgi_params<span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="o">}</span>
</span></span><span class="line"><span class="cl">        location /media <span class="o">{</span>
</span></span><span class="line"><span class="cl">            <span class="nb">alias</span> /home/meruro/projects/DjangoBlog/media<span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="o">}</span>
</span></span><span class="line"><span class="cl">        location /static <span class="o">{</span>
</span></span><span class="line"><span class="cl">            <span class="nb">alias</span> /home/meruro/projects/DjangoBlog/static<span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="o">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1">#error_page  404              /404.html;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1"># redirect server error pages to the static page /50x.html</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#</span>
</span></span><span class="line"><span class="cl">        error_page   <span class="m">500</span> <span class="m">502</span> <span class="m">503</span> <span class="m">504</span>  /50x.html<span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="nv">location</span> <span class="o">=</span> /50x.html <span class="o">{</span>
</span></span><span class="line"><span class="cl">            root   html<span class="p">;</span>
</span></span><span class="line"><span class="cl">        <span class="o">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1"># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#location ~ \.php$ {</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#    proxy_pass   http://127.0.0.1;</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="c1"># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#location ~ \.php$ {</span>
</span></span><span class="line"><span class="cl">        <span class="c1">#    root           html;</span>
</span></span><span class="line"><span class="cl">		<span class="c1">#    </span>
</span></span><span class="line"><span class="cl">		 upstream django <span class="o">{</span>
</span></span><span class="line"><span class="cl">			server 127.0.0.1:8080<span class="p">;</span>
</span></span><span class="line"><span class="cl">		<span class="o">}</span>
</span></span><span class="line"><span class="cl">		    server <span class="o">{</span>
</span></span><span class="line"><span class="cl">		        listen       <span class="m">443</span> ssl<span class="p">;</span>
</span></span><span class="line"><span class="cl">		        server_name  localhost<span class="p">;</span>
</span></span><span class="line"><span class="cl">		
</span></span><span class="line"><span class="cl">		        ssl_certificate      /etc/nginx/ssl/1_meruro.cn_bundle.crt<span class="p">;</span>
</span></span><span class="line"><span class="cl">		        ssl_certificate_key  /etc/nginx/ssl/2_meruro.cn.key<span class="p">;</span>
</span></span><span class="line"><span class="cl">		
</span></span><span class="line"><span class="cl">		        ssl_session_cache    shared:SSL:1m<span class="p">;</span>
</span></span><span class="line"><span class="cl">		        ssl_session_timeout  5m<span class="p">;</span>
</span></span><span class="line"><span class="cl">		
</span></span><span class="line"><span class="cl">		        ssl_ciphers  HIGH:!aNULL:!MD5<span class="p">;</span>
</span></span><span class="line"><span class="cl">		        ssl_prefer_server_ciphers  on<span class="p">;</span>
</span></span><span class="line"><span class="cl">		
</span></span><span class="line"><span class="cl">		        location / <span class="o">{</span>
</span></span><span class="line"><span class="cl">		            root   html<span class="p">;</span>
</span></span><span class="line"><span class="cl">		            index  index.html index.htm<span class="p">;</span>
</span></span><span class="line"><span class="cl">		        <span class="o">}</span>
</span></span><span class="line"><span class="cl">		    <span class="o">}</span>
</span></span><span class="line"><span class="cl">		
</span></span><span class="line"><span class="cl">		<span class="o">}</span>
</span></span><span class="line"><span class="cl">		
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">-- VISUAL LINE --
</span></span></code></pre></td></tr></table>
</div>
</div>
</section>


    <footer class="article-footer">
    
    <section class="article-tags">
        
            <a href="/tags/%E4%BB%A3%E7%A0%81/">代码</a>
        
    </section>


    
    <section class="article-copyright">
        <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copyright" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="12" r="9" />
  <path d="M14.5 9a3.5 4 0 1 0 0 6" />
</svg>



        <span>Licensed under CC BY-NC-SA 4.0</span>
    </section>
    </footer>


    
</article>

    

    

     
    
        
    

    <footer class="site-footer">
    <section class="copyright">
        &copy; 
        
            2020 - 
        
        2023 梅鲁梅鲁梅鲁梅~
    </section>
    
    <section class="powerby">
        Built with <a href="https://gohugo.io/" target="_blank" rel="noopener">Hugo</a> <br />
        Theme <b><a href="https://github.com/CaiJimmy/hugo-theme-stack" target="_blank" rel="noopener" data-version="3.13.0">Stack</a></b> designed by <a href="https://jimmycai.com" target="_blank" rel="noopener">Jimmy</a>
    </section>
</footer>


    
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    
    <div class="pswp__bg"></div>

    
    <div class="pswp__scroll-wrap">

        
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                
                
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"integrity="sha256-ePwmChbbvXbsO02lbM3HoHbSHTHFAeChekF1xKJdleo="crossorigin="anonymous"
                defer
                >
            </script><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"integrity="sha256-UKkzOn/w1mBxRmLLGrSeyB4e1xbrp4xylgAWb3M42pU="crossorigin="anonymous"
                defer
                >
            </script><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css"crossorigin="anonymous"
            ><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css"crossorigin="anonymous"
            >

            </main>
    <aside class="sidebar right-sidebar sticky">
        
            
                
    <section class="widget archives">
        <div class="widget-icon">
            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-hash" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <line x1="5" y1="9" x2="19" y2="9" />
  <line x1="5" y1="15" x2="19" y2="15" />
  <line x1="11" y1="4" x2="7" y2="20" />
  <line x1="17" y1="4" x2="13" y2="20" />
</svg>



        </div>
        <h2 class="widget-title section-title">Table of contents</h2>
        
        <div class="widget--toc">
            <nav id="TableOfContents">
  <ol>
    <li><a href="#1-安装python36">1. 安装python3.6</a></li>
    <li><a href="#2-maridb">2. maridb</a></li>
    <li><a href="#3-安装nginx">3. 安装nginx</a></li>
    <li><a href="#配置文件">配置文件</a></li>
  </ol>

  <ol>
    <li><a href="#发送所有请求经uwsgi转接">发送所有请求经uwsgi转接</a></li>
  </ol>
</nav>
        </div>
    </section>

            
        
    </aside>


        </div>
        <script 
                src="https://cdn.jsdelivr.net/npm/node-vibrant@3.1.6/dist/vibrant.min.js"integrity="sha256-awcR2jno4kI5X0zL8ex0vi2z&#43;KMkF24hUW8WePSA9HM="crossorigin="anonymous"
                
                >
            </script><script type="text/javascript" src="/ts/main.js" defer></script>
<script>
    (function () {
        const customFont = document.createElement('link');
        customFont.href = "https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&display=swap";

        customFont.type = "text/css";
        customFont.rel = "stylesheet";

        document.head.appendChild(customFont);
    }());
</script>

    </body>
</html>
